use actix_web::{get, web, Responder};

use crate::learn::learn_struct;

// pub mod struct_controller {

#[get("/try_struct")]
async fn try_struct_handler() -> impl Responder {
    let (user1, user2) = learn_struct::try_struct1();
    // format!(
    //     "User1: {}, {}, {}\nUser2: {}, {}, {}",
    //     user1.name, user1.age, user1.email, user2.name, user2.age, user2.email
    // )
    let black = learn_struct::try_struct2();
    web::Json(serde_json::json!(
        { "user1": user1, "user2": user2, "black": black.0, "r": black.1, "g": black.2, "b": black.3 }
    ))
}

#[get("/try_struct_rect")]
async fn try_struct_rectangle() -> impl Responder {
    let rect = learn_struct::Rectangle {
        width: 30,
        height: 50,
    };
    let area = rect.area();
    web::Json(serde_json::json!(
        { "width": rect.width, "height": rect.height, "area": area }
    ))
}

#[get("/try_option")]
async fn try_option() -> impl Responder {
    let five = Some(5);
    web::Json(serde_json::json!(
        { "five": five, "plus_one": learn_struct::option::plus_one(five), "none": learn_struct::option::plus_one(None) }
    ))
}
